package com.baizhi.listx;

import java.util.ArrayList;
import java.util.List;

public class Homework {
    public static void main(String[] args) {
        List<Student> sts = new ArrayList<>();
        sts.add(new Student("张三",17));
        sts.add(new Student("李四",25));
        sts.add(new Student("林工",15));
        sts.add(new Student("陈红",17));
        sts.add(new Student("李林",18));

        //sts.forEach(System.out::println);

        //输出学生姓名中含有林的学生信息
        for (Student st : sts) {
            //获取学生名字
            String name = st.getName();
            //把nane转换成char数组
            char[] chars = name.toCharArray();
            for (char a : chars) {
                if('林'==a){
                    System.out.println(st);
                }
            }
        }



//        //输出学生姓名中含有林的学生信息
//        for (int i = 0; i < sts.size(); i++) {
//            Student student = sts.get(i);
//            //获取学生名字
//            String name = student.getName();
//            //从名字中找是否有林出现
//            int num = name.indexOf("林");
//            if(num != -1){
//                System.out.println(student);
//            }
//        }

    }
}



class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
